package com.wjsima.renyisima.demo;

import java.util.*;
import java.util.function.Supplier;

public class HomeWork11 {
    public static <T> T getObj(Supplier<T> supplier) {
        return supplier.get();
    }



    public static void main(String[] args) {
//        String[] st = getObj(() -> new String[5]);
//        System.out.println(st.length);
//        HashSet hs = getObj((Supplier<HashSet>) () -> {
//            Random r = new Random();
//            HashSet<Integer> hs1 = new HashSet<>();
////            for (int i = 0; i < 5; i++) {
////
////                hs1.add(r.nextInt(20) + 1);
////
////           }
//            while(hs1.size() != 5){
//                hs1.add(r.nextInt(20) + 1);
//            }
//            return hs1;
//        });
//        System.out.println(hs);
////        一个代表2018年4月1日的Calendar对象r
//        Calendar r1 = getObj(() -> {
//            Calendar instance = Calendar.getInstance();
//            instance.set(2018,04,01);
//            return instance;
//        });
        Supplier<String[]> su = new Supplier<String[]>() {
            @Override
            public String[] get() {
                String[] s = new String[5];
                return s;
            }
        };
        String[] s = getObj(su);
        System.out.println(s.length);
        Random r = new Random();

        Supplier<HashSet<Integer>> sup = new Supplier<HashSet<Integer>>() {
            @Override
            public HashSet<Integer> get() {
                HashSet<Integer> s = new HashSet<>();
                while(s.size() != 5) {
                    int i = r.nextInt(20) + 1;
                    s.add(i);
                }
                return s;

            }
        };
        HashSet<Integer> in = getObj(sup);
        System.out.println(in);
        Supplier<Calendar> supp = new Supplier<Calendar>() {
            @Override
            public Calendar get() {
                Calendar c = Calendar.getInstance();
                c.set(2018,3,1);

                return c;
            }

        };
        Calendar c = getObj(supp);

        System.out.println(c.getTime().toLocaleString());


    }
}